import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/basicIntroduction',
    component: Layout,
    name: 'basicIntroduction',
    children: [
      {
        path: 'index',
        name: 'basicIntroduction',
        component: () => import('@/views/project/basicIntroduction'),
        meta: { title: '实验基本介绍', icon: 'el-icon-s-platform' }
      }
    ]
  },
  {
    path: '/Preview',
    component: Layout,
    name: 'Preview',
    children: [
      {
        path: 'index',
        name: 'Preview',
        component: () => import('@/views/project/Preview'),
        meta: { title: '实验内容预习', icon: 'el-icon-document' }
      }
    ]
  },
  {
    path: '/Instrument',
    component: Layout,
    name: 'Instrument',
    children: [
      {
        path: 'Instrument',
        name: 'Instrument',
        component: () => import('@/views/project/Instrument'),
        meta: { title: '实验仪器介绍', icon: 'el-icon-odometer' }
      }
    ]
  },
  {
    path: '/imageDisplay',
    component: Layout,
    name: 'imageDisplay',
    children: [
      {
        path: 'imageDisplay',
        name: 'imageDisplay',
        component: () => import('@/views/project/imageDisplay'),
        meta: { title: '实验图片展示', icon: 'el-icon-picture-outline' }
      }
    ]
  },
  {
    path: '/thinkingAndPrompts',
    component: Layout,
    name: 'thinkingAndPrompts',
    children: [
      {
        path: 'thinkingAndPrompts',
        name: 'thinkingAndPrompts',
        component: () => import('@/views/project/thinkingAndPrompts'),
        meta: { title: '思考题以及提示', icon: 'el-icon-s-opportunity' }
      }
    ]
  },
  {
    path: '/reference',
    component: Layout,
    name: 'reference',
    children: [
      {
        path: 'reference',
        name: 'reference',
        component: () => import('@/views/project/reference'),
        meta: { title: '参考资料', icon: 'el-icon-collection' }
      }
    ]
  },
  {
    path: '/feeling',
    component: Layout,
    name: 'feeling',
    children: [
      {
        path: 'feeling',
        name: 'feeling',
        component: () => import('@/views/project/feeling'),
        meta: { title: '心得体会', icon: 'el-icon-collection' }
      }
    ]
  },



  // {
  //   path: '/project',
  //   component: Layout,
  //   name: 'project',
  //   alwaysShow: true,
  //   meta: { title: '实验项目管理', icon: 'el-icon-s-platform' },
  //   children: [
  //     {
  //       path: '/userList',
  //       name: 'userList',
  //       component: () => import('@/views/system/userList'),
  //       meta: { title: '实验基本介绍', icon: 'el-icon-s-custom' }
  //     },
  //     {
  //       path: '/roleList',
  //       name: 'roleList',
  //       component: () => import('@/views/system/roleList'),
  //       meta: { title: '角色管理', icon: 'el-icon-place' }
  //     },
  //     {
  //       path: '/menuList',
  //       name: 'menuList',
  //       component: () => import('@/views/system/menuList'),
  //       meta: { title: '权限管理', icon: 'tree' }
  //     },
  //   ]
  // },
  // {
  //   path: '/House',
  //   component: Layout,
  //   name: 'House',
  //   alwaysShow: true,
  //   meta: { title: '房屋管理', icon: 'el-icon-office-building' },
  //   children: [
  //     {
  //       path: '/houseList',
  //       name: 'houseList',
  //       component: () => import('@/views/house/houseList'),
  //       meta: { title: '房屋列表', icon: 'el-icon-house' }
  //     }
  //   ]
  // },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const constantRoutes2 = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },
  {
    path: '/userManage',
    component: Layout,
    name: 'userManage',
    children: [
      {
        path: '/userManage',
        name: 'userManage',
        component: () => import('@/views/project/userManage'),
        meta: { title: '用户管理', icon: 'el-icon-collection' }
      }
    ]
  },
]


export const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: test()
})

// const createRouter2 = () => new Router({
//   // mode: 'history', // require service support
//   mode: 'hash',
//   scrollBehavior: () => ({ y: 0 }),
//   routes: constantRoutes2
// })

const test = () => {
  let route = ''
  const type = localStorage.getItem("type");
  console.log('11111111111111111111111111');
  console.log('type：'+type);
  if(type==0){
    route=constantRoutes2
  }else{
    route=constantRoutes
  }
  // route = (type == '0' ? constantRoutes2 : constantRoutes)
  // location.reload()
  // this.$router.go(0)
  return route
}

const router = createRouter()






// const createRouter = () => new Router({
//   // mode: 'history', // require service support
//   mode: 'hash',
//   scrollBehavior: () => ({ y: 0 }),
//   routes: constantRoutes
// })

// const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  console.log('123');
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
